package invest.strategy.impl;


import invest.data.DataEnum;
import invest.data.DataFactory;
import invest.pojo.ToSendRecord;
import invest.pojo.datapojo.Stock;
import invest.strategy.Variable;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.text.ParseException;
import java.time.LocalTime;
import java.util.List;

@Component
public class ShouPanRiNei extends AbstractStrategy {
    {
        super.cron = "0 45/1 14-15 ? * MON-FRI";
    }

    DataFactory dataFactory = new DataFactory();




    //邮件内容，必填
    @Override
    protected void setMail() {
        mail.setSubject("开盘跌百分之3，日内涨幅大于8");
        mail.setContent("股快速上涨，快速进行买入");
    }

    @Override
    public boolean analyzeStrategy() throws ParseException, IOException {
        LocalTime currentTime = LocalTime.now();  // 获取当前时间
        LocalTime targetTime = LocalTime.of(9, 30, 0);  // 上午九点半
        if (currentTime.isBefore(targetTime)) {
            return false;
        }
        Boolean flag=false;
        List<Stock> stockList = (List<Stock>) dataFactory.getData(DataEnum.STOCK_REALTIME);
        for (Stock s : stockList) {
            try {
                String symbol = s.getSymbol();
                if (!Variable.openPrice.containsKey(symbol)) {
                    continue;
                }
                if (Variable.openPrice.get(symbol).getPercent() < -3 && s.getPercent()- Variable.openPrice.get(symbol).getPercent()>7 && s.getPercent()<9.9&& s.getPercent()>6) {
                    ToSendRecord record = new ToSendRecord();
                    record.setName(s.getName());
//                    record.setMessage("开盘跌，日内涨");
                    this.setToSendTarget(record);
                    flag = true;
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

        }
        return flag;
    }
}
